# 模型转换为po,vo,dto等

def one_to_dict(book):
    file_info = book.file_id
    type_info = book.type_info
    return {
        "id": str(book.id),
        "bookNo": book.book_no,
        "bookName": book.book_name,
        "bookAuthor": book.book_author,
        "typeId": str(type_info.type_id),
        "typeName": type_info.type_name,
        "fileId": str(file_info.file_id),
        "fileUrl": file_info.file_url,
        "createDate": book.create_date.strftime("%Y-%m-%d %H:%M:%S"),
        "createUser": book.create_user,
        "updateDate": book.update_date.strftime("%Y-%m-%d %H:%M:%S"),
        "updateUser": book.update_user,
        "version": book.version
    }


def to_dict_pos(books):
    return [one_to_dict(book) for book in books]


class BookResponse:
    def __init__(self, book):
        self.id = str(book.id)
        self.bookNo = book.book_no
        self.bookName = book.book_name
        self.bookAuthor = book.book_author
        self.typeId = str(book.type_id)
        self.fileId = str(book.file_id)
        self.createDate = book.create_date.strftime("%Y-%m-%d %H:%M:%S")
        self.createUser = book.create_user
        self.updateDate = book.update_date.strftime("%Y-%m-%d %H:%M:%S")
        self.updateUser = book.update_user
        self.version = book.version
